// 所有公共的请求的数据和方法

import { reactive, ref } from "vue";
import { searchDoctorsApi } from "../api/doctors";
import { searchOrganizationsApi } from "../api/organizations";
import { searchRoleApi } from "../api/role";
import { searchTeamsApi } from "../api/teamManage";
import { searchServiceApi } from "../api/service";
import { getServicePackageApi, getServicePacksgeTypeApi } from "../api/servicePacksge";
import { searchServiceItemApi } from "../api/serviceItem";
import { getTagApi } from "../api/tag";


export function useFindData() {
  // 医生数据
  const doctorData = reactive({
    rows: [],
    total: 0
  })
  // 机构的数据
  const organizationsData = reactive({
    rows: [],
    total: 0
  })
  // 角色的数据
  const roleData = reactive({
    rows: [],
    total: 0
  })
  // 团队数据
  const teamData = reactive({
    rows: [],
    total: 0
  })
  // 服务记录的数据
  const serviceLogData = reactive({
    rows: [],
    total: 0
  })
  // 服务包分类的数据
  const servicePackageTypeData = ref([])
  // 分页查询服务包的数据
  const servicePackageData = reactive({
    rows: [],
    total: 0
  })
  // 获取服务项目的数据
  const serviceItemsData = reactive({
    rows: [],
    total: 0
  })
  // 获取标签的数据
  const tagData = reactive({
    rows: [],
    total: 0
  })
  // 获取医生的请求
  function findDoctorDataAsync(data) {
    searchDoctorsApi(data).then(res => {
      if (res.code == 200) {
        doctorData.rows = res.data.rows
        doctorData.total = res.data.total
      }
    })
  }
  // 获取机构的请求
  function findOrganizationsDataAsync(data) {
    searchOrganizationsApi(data).then(res => {
      if (res.code == 200) {
        organizationsData.rows = res.data.rows
        organizationsData.total = res.data.total
      }
    })
  }
  // 获取角色的请求
  function getRoleDataAsync(data) {
    searchRoleApi(data).then(res => {
      if (res.code == 200) {
        roleData.rows = res.data.rows
        roleData.total = res.data.total
      }
    })
  }
  // 获取团队的请求
  function getTeamDataAsync(data) {
    searchTeamsApi(data).then(res => {
      if (res.code == 200) {
        teamData.rows = res.data.rows
        teamData.total = res.data.total
      }
    })
  }
  // 获取服务的请求
  function getServiceLogDataAsync(data) {
    searchServiceApi(data).then(res => {
      if (res.code == 200) {
        serviceLogData.rows = res.data.rows
        serviceLogData.total = res.data.total
      }
    })
  }
  // 获取服务包分类的请求
  function getServicePackageTypeAsync(data) {
    getServicePacksgeTypeApi(data).then(res => {
      if (res.code == 200) {
        servicePackageTypeData.value = res.data
      }
    })
  }
  // 分页查询服务包的数据的请求
  function getServicePackageDataAsync(data) {
    getServicePackageApi(data).then(res => {
      if (res.code == 200) {
        servicePackageData.rows = res.data.rows
        servicePackageData.total = res.data.total
      }
    })
  }
  // 获取服务项目的请求
  function getServiceItemAsync(data) {
    searchServiceItemApi(data).then(res => {
      if (res.code == 200) {
        serviceItemsData.rows = res.data.rows
        serviceItemsData.total = res.data.total
      }
    })
  }
  // 获取标签的请求
  function getTagAsync(data) {
    getTagApi(data).then(res => {
      if (res.code == 200) {
        tagData.rows = res.rows
        tagData.total = res.total
      }
    })
  }
  return {
    doctorData, findDoctorDataAsync,
    organizationsData, findOrganizationsDataAsync,
    roleData, getRoleDataAsync,
    teamData, getTeamDataAsync,
    serviceLogData, getServiceLogDataAsync,
    servicePackageTypeData, getServicePackageTypeAsync,
    servicePackageData, getServicePackageDataAsync,
    serviceItemsData, getServiceItemAsync,
    tagData, getTagAsync
  }
}